package LC;

/**
 * https://leetcode.com/problems/climbing-stairs/description/
 * You are climbing a stair case. It takes n steps to reach to the top.
 * Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
 * Note: Given n will be a positive integer.
 */
public class LC_070_ClimbingStairs_Recur {
    public static void main(String[] args) {
        int res = Solution.climbStairs(4);
        System.out.println(res);
    }

    static class Solution {
        static int climbStairs(int n) {
            int[] flags = new int[n + 1];
            for (int i = 0; i <= n; i++)
                flags[i] = -1;
            return climbStairs(flags, n);
        }

        private static int climbStairs(int[] flags, int n) {
            if (flags[n] != -1)
                return flags[n];
            if (n == 1 || n == 0) {
                flags[n] = 1;
                return 1;
            } else {
                flags[n] = climbStairs(flags, n - 1) + climbStairs(flags, n - 2);
                return flags[n];
            }
        }
    }
}
